/*
Copyright 2010-2011 CumulusCloud
http://cumuluscloud.cc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cumulusCloud.common;

import cumulusCloud.common.objects.CloudUser;
import cumulusCloud.knowledge.UserKnow;

/**
 * This class gives information and can modify the cloud users
 * 
 * @author Simon Levesque
 *
 */
public class ManageUser {
	private static UserKnow know = UserKnow.getInstance();
	
	/**
	 * Create a user
	 * 
	 * @param user The user information
	 * @return True if it could be created
	 */
	public static boolean createUser(CloudUser user) {
		return know.createUser(user);
	}
	
	/**
	 * Delete a user
	 * 
	 * @param user The username
	 * @return True if it existed
	 */
	public static boolean deleteUser(String user) {
		return know.deleteUser(user);
	}
	
	/**
	 * Get the cloud user by its name
	 * 
	 * @param user The username
	 * @return The user
	 */
	public static CloudUser getUser(String user) {
		return know.getUser(user);
	}
	
	/**
	 * Check if a user exists and if its password is the right one
	 * 
	 * @param user The username
	 * @param password The password to test
	 * @return True if the user exists and the password is the right one
	 */
	public static boolean isValidCredential(String user, String password) {
		return know.isValidCredential(user, password);
	}
	
	/**
	 * Get a list of all the users on the cloud
	 * 
	 * @return The users
	 */
	public static CloudUser[] listUsers() {
		return know.listUsers();
	}
	
	/**
	 * Change any parameter of a user. The password must be unencoded in the modified user (if changed)
	 * 
	 * @param previous The user has currently known in the system
	 * @param modified A cloned user with the new values
	 * @return True if could be modified successfully
	 */
	public static boolean modifyUser(CloudUser previous, CloudUser modified) {
		return know.modifyUser(previous, modified);
		
	}
}
